/* eslint-disable no-unused-vars */
import axios from '@/libs/api.request'
import config from '@/config'
import { Message } from 'iview'

export const getInfo = () => {
  return axios.request({
    url: 'sys/user/getInfo',
    method: 'get'
  })
}

export const updatePassword = (formItem) => {
  return axios.request({
    url: 'sys/user/updatePassword',
    method: 'post',
    data: {
      'password': formItem.password,
      'newPassword': formItem.newPassword,
      'confirmPassword': formItem.confirmPassword
    }
  })
}

export const updateUser = (form) => {
  return axios.request({
    url: 'sys/user/updateUser',
    method: 'post',
    data: form
  })
}

export const uploadAvatar = (form) => {
  return axios.request({
    url: 'sys/user/uploadAvatar',
    method: 'post',
    data: form
  })
}

export const info = (userId) => {
  return axios.request({
    url: 'sys/user/info/' + userId,
    method: 'get'
  })
}

export const saveOrUpdateSysUserInfo = (obj) => {
  let path = ''
  if (typeof (obj.userId) === 'undefined') {
    path = 'sys/user/save'
  } else {
    path = 'sys/user/update'
    if (config.preview) {
      Message.error('演示模式不允许修改')
      return
    }
  }
  return axios.request({
    url: path,
    method: 'post',
    data: obj
  })
}

export const updateStatus = (userId, status) => {
  return axios.request({
    url: 'sys/user/updateStatus',
    method: 'post',
    data: {
      'userId': userId,
      'status': status
    }
  })
}

export const deleteUser = (userId) => {
  const data = [userId]
  return axios.request({
    url: 'sys/user/delete',
    method: 'post',
    data: data
  })
}
